package cn.iotab.iotkit.transport.api.access.handler.support;

import cn.iotab.iotkit.transport.api.access.TransportAccessService;
import cn.iotab.iotkit.transport.api.common.message.ToTransportMessage;
import cn.iotab.iotkit.transport.api.common.message.msg.CommonPayload;
import cn.iotab.iotkit.transport.api.common.message.msg.down.CloseSessionCmd;
import cn.iotab.iotkit.transport.api.common.queue.SendResultCallback;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ToTransportMessageSender {

    private final TransportAccessService accessService;

    public ToTransportMessageSender(TransportAccessService accessService) {
        this.accessService = accessService;
    }

    public void sendToDeviceRequest(String sessionId, CommonPayload request, SendResultCallback<Void> callback){
        ToTransportMessage toTransportMessage = new ToTransportMessage();
        toTransportMessage.setSessionId(sessionId);
        toTransportMessage.setToDeviceRequest(request);
        //send
        accessService.sendToTransportMsg(toTransportMessage, callback);
    }

    public void sendToDeviceResponse(String sessionId, CommonPayload response, SendResultCallback<Void> callback){
        ToTransportMessage toTransportMessage = new ToTransportMessage();
        toTransportMessage.setSessionId(sessionId);
        toTransportMessage.setToDeviceResponse(response);
        //send
        accessService.sendToTransportMsg(toTransportMessage, callback);
    }

    public void sendCloseSessionCmd(String sessionId, CloseSessionCmd cmd, SendResultCallback<Void> callback){
        ToTransportMessage toTransportMessage = new ToTransportMessage();
        toTransportMessage.setSessionId(sessionId);
        toTransportMessage.setCloseSessionCmd(cmd);
        //send
        accessService.sendToTransportMsg(toTransportMessage, callback);
    }

}
